#! /bin/bash
clear
echo -e "Get Parameters:"
echo "input your STUDENT ID:"
read stuid
echo "your student ID is $stuid"
nmcli con show > /dev/null
net=$(nmcli con show | head -n 2 | tail -n 1 | cut -d ' ' -f 1)
echo "connection name: $net"
echo "===================================================================="
echo "Start Setting..."
echo "--------------------------------------------------------------------"
echo "step 1: close selinux"
echo "SELINUX Status:$(getenforce)"
if [ "$(getenforce)" = "Enforce" ]; then 
	setenforce 0
	echo "Set SELINUX Status:$(getenforce),Success!"
fi
sed -i "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config
sedstat=$?
if [ $sedstat -eq 0 ]; then
	echo "The configuration file has been modified successfully." 
fi
echo "--------------------------------------------------------------------"
echo "step 2: close firewalld"
systemctl stop firewalld
systemctl disable firewalld
if [ "$?" == "0" ]; then
	echo "The firewalld service has been stopped successfully."
fi
#systemctl status firewalld
echo "--------------------------------------------------------------------"
echo "step 3: set network address"
echo "Interface Name is:$net"
nmcli con mod $net ipv4.method manual ipv4.address 10.0.$stuid.101/24 ipv4.gateway 10.0.$stuid.254
nmcli con reload
nmcli con down $net > /dev/null && nmcli con up $net > /dev/null
ip addr show $net | head -n 4 | tail -n 1
echo "The network configuration has been completed! "
echo "--------------------------------------------------------------------"
echo "step 4: set yum repo"
#mkdir /mnt/Rocky
#echo "/dev/sr0 /mnt/Rocky iso9660 defaults 0 0" >> /etc/fstab
mount -a
#mkdir /etc/yum.repos.d/bak
cd /etc/yum.repos.d
#mv *.repo bak
echo "[local-baseos]" > local.repo
echo "name=Local BaseOS" >> local.repo
echo "baseurl=file:///mnt/Rocky/BaseOS" >> local.repo
echo "gpgcheck=0" >> local.repo
echo "enabled=1" >> local.repo
echo "[local-appstream]" >> local.repo
echo "name=Local AppStream" >> local.repo
echo "baseurl=file:///mnt/Rocky/AppStream" >> local.repo
echo "gpgcheck=0" >> local.repo
echo "enabled=1" >> local.repo
dnf repolist
dnf clean all > /dev/null
dnf makecache > /dev/null
if [ "$?" = "0" ]; then
	echo "The yum repository configuration was successful."
fi
echo "===================================================================="
echo "Congratulation! You have completed all the configurations!"
